const Service = require('egg').Service;

/**
 * 接口数据   管理
 */
class ApiDataService extends Service {
	tableName = 'mock-api';
	// 接口查询
	async queryApi(id) {
		const { ctx, app, service } = this;
		/**
		 * 查询所有分类接口
		 * 
		 * 判断是否有传入id,如果有就查询单条数据
		 */
		if (id !== undefined) {
			return await app.mongo.findOne(this.tableName, {
				query: {
					_id: app.getObjectId(id)
				}
			});
		}
		
		const res = await app.mongo.find(this.tableName, {});
		return res;
	}
}

module.exports = ApiDataService;
